var log = console.log;
// ip地址
var str = 'sldkeifjd kiekjfjks slsk127.0.0.1 dkkd ekks  192.168.0.101 ksdkkd kskd function dd () { }kdiejsk kskd function abc(){}idksk';
var reg = /(\d{1,3}\.){3}\d{1,3}/g;
var arr;
log('\r\n**************匹配的地址******************');
while((arr=reg.exec(str)) != null){
    log(arr[0]);
}
// 函数
var reg2 = /function\s+[a-zA-Z$_][\w$]*\s*\((\s*[a-zA-Z$_][\w$]*\s*)?\)\s*\{\s*\}/g;
var arr2;
log('\r\n**************匹配的函数******************');
while((arr2=reg2.exec(str)) != null){
    log(arr2[0]);
}

var a1 = [1,2,3];
// var a2 = [4,5,6];
var a2 = [4,5,6,7,8];
function a12(a1,a2){
    var newArr = [];
    for(var i=0; i<Math.max(a1.length, a2.length); i++){
        if(i<a1.length) newArr.push(a1[i]);
        if(i<a2.length) newArr.push(a2[i]);
    }
    return newArr;
}
log('\r\n**************合并的数组******************');
log(a12(a1,a2));

// var time1 = setInterval(function(){
//     shaizi(2);
// },1000);
log('\r\n***************骰子的点数*****************');
shaizi(2);
function shaizi(num){
    var sum = 0;
    if(num==1){
        sum =  Math.floor(Math.random()*5+1);
    }else if(num>1){
        for(var i=0; i<num; i++){
            sum += Math.floor(Math.random()*5+1);
        }
    }
    if(sum>num*6){
        log('############# 错误: '+sum+' ################');
        clearInterval(time1);
    }else if(sum==num*6){
        log('############# '+sum+' ################');
        clearInterval(time1);
    }else{
        log(num+'个骰子点数: '+sum);
    }
}



// sleep
function sleep(time){
    return new Promise(function(resolve,reject){
        setTimeout(resolve,time);
    });
}

async function test(){
    log('当前秒数: '+new Date().getSeconds());
    await sleep(2000);
    log('2秒后秒数: '+new Date().getSeconds());
    await sleep(1000);
    log('1秒后秒数: '+new Date().getSeconds());
}
log('\r\n***************等待执行*****************');
test();
